package org.vincen.server5async;

import java.util.concurrent.Future;

import javax.jws.WebService;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;

import org.apache.hello_world_async_soap_http.GreeterAsync;
import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;

@WebService(serviceName = "SOAPService",
			portName = "GreeterAsync",
			targetNamespace = "http://apache.org/hello_world_async_soap_http",
			wsdlLocation = "Greeter2.wsdl",
			endpointInterface = "org.apache.hello_world_async_soap_http.GreeterAsync")
public class GreeterAsyncImpl implements GreeterAsync {

	/*
	 * 返回值类型为Response<GreetMeSometimeResponse>的sayHiAsync()方法 ——
	 * 该方法可用于异步调用的轮询方式。
	 * 
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.hello_world_async_soap_http.GreeterAsync#greetMeSometimeAsync
	 * (java.lang.String)
	 */
	@Override
	public Response<GreetMeSometimeResponse> greetMeSometimeAsync(
			String requestType) {
		return null;
	}

	/*
	 * 返回值类型为Future<?>，有一个类型为javax.xml.ws.AsyncHandler的额外参数的sayHiAsync()方法 ——
	 * 该方法可用于异步调用的回调方式。
	 * 
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.hello_world_async_soap_http.GreeterAsync#greetMeSometimeAsync
	 * (java.lang.String, javax.xml.ws.AsyncHandler)
	 */
	@Override
	public Future<?> greetMeSometimeAsync(String requestType,
			AsyncHandler<GreetMeSometimeResponse> asyncHandler) {
		return null;
	}

	@Override
	public String greetMeSometime(String requestType) {
	    String retVal = null;  
	    if(null == requestType){  
	        retVal = "Error: request object null !";  
	    }else{  
	        try{  
	            System.out.println("sleep for 4 seconds before return");  
	            Thread.sleep(4000);  
	        }catch(InterruptedException e){  
	            e.printStackTrace();  
	        }  
	          
	        System.out.println("greetMeSometime called by: " + requestType);  
	        retVal = "Hello " + requestType;  
	    }  
	    return retVal;  
	}

}
